//
//  SYS_SearchView.m
//  System_App
//
//  Created by czy001 on 2017/12/4.
//  Copyright © 2017年 czy001. All rights reserved.
//

#import "SYS_SearchView.h"

@implementation SYS_SearchView

- (id)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor=RGBACOLOR(242, 242, 242, 1);
        
        UIView *bjView=[[UIView alloc] initWithFrame:CGRectMake(15, 0, SCREENWIDTH-30, 38)];
        bjView.backgroundColor=[UIColor whiteColor];
        bjView.layer.cornerRadius=19;
        bjView.layer.masksToBounds=YES;
        [self addSubview:bjView];
        
        _inputTF=[[SYS_CustomFiled alloc] initWithFrame:CGRectMake(20, 4, SCREENWIDTH-100, 30)];
        _inputTF.delegate=self;
        _inputTF.tintColor=MainColor;
        _inputTF.returnKeyType=UIReturnKeySearch;
        _inputTF.clearButtonMode=UITextFieldViewModeWhileEditing;
        _inputTF.font=[UIFont systemFontOfSize:12];
        [bjView addSubview:_inputTF];
        
        _searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _searchBtn.frame=CGRectMake(SCREENWIDTH-30-35, 4, 30, 30);
        [_searchBtn setImage:[UIImage imageNamed:@"message_sousu"] forState:UIControlStateNormal];
        [_searchBtn addTarget:self action:@selector(buttonClickSearchButton) forControlEvents:UIControlEventTouchUpInside];
        [bjView addSubview:_searchBtn];
    }
    return self;
}

- (void)buttonClickSearchButton
{
    if (_delegate && [_delegate respondsToSelector:@selector(buttonClickSearchBtnWithKeyword:)]) {
        if (_inputTF.text.length>0) {
            [_delegate buttonClickSearchBtnWithKeyword:_inputTF.text];
        }
    }
}

- (void)setPlaceholder:(NSString *)placeholder
{
    _inputTF.placeholder=placeholder;
}

- (void)setIsClickChange:(BOOL)isClickChange
{
    _isClickChange=isClickChange;
}

#pragma mark---UITextFieldDelegate
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    if (_delegate && [_delegate respondsToSelector:@selector(goSearchResultVC)]) {
        [_delegate goSearchResultVC];
    }
    return !_isClickChange;
}

@end
